<template>
    <h2>登录页面</h2>
    <table border="1" class="table table-bordered">
        <tr>
            <td>用户名</td>
            <td>
                <input type="text" placeholder="请输入用户名" v-model="info.ML_Name" />
            </td>
        </tr>
        <tr>
            <td>密码</td>
            <td>
                <input type="password" placeholder="请输入密码" v-model="info.ML_Pwd" />
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="登录" class="btn btn-success" @click="login"/>
            </td>
        </tr>
    </table>
</template>

<script setup lang="ts">
    import {ref} from 'vue'
    import {useRouter} from 'vue-router'
    import axios from 'axios'
    const router=useRouter();
     const info=ref({
        "ML_Name": "",
  "ML_Pwd": ""
     })

     const login=()=>{
        if(info.value.ML_Name=="")
        {
            alert('用户名不能为空');
            return;
        }
        if(info.value.ML_Pwd=="")
        {
            alert('密码不能为空');
            return;
        }
        axios.get('https://localhost:44320/api/Member/MemberLogin',{
            params:{
                "mname":info.value.ML_Name,
                "pwd": info.value.ML_Pwd
            }
        })
      .then(res=>{
        console.log(res.data);
        if(res.data.LoginCode==0)
        {
            alert(res.data.LoginMessage);
        }
        else if(res.data.LoginCode==1)
        {
            alert(res.data.LoginMessage);
        }
        else if(res.data.LoginCode==3)
        {
            console.log(res.data.LoginList[0]);
            alert(res.data.LoginMessage);
            // router.push({
            //     path:'/addMemberInfo',
            //     query:{mI_Id:res.data.LoginList[0].ML_Id}
            // })
            SearchMemberInf(res.data.LoginList[0].ML_Id);

            // router.push({
            //     name:"addMemberInfo",
            //     params:{
            //         mL_Id:res.data.LoginList[0].ML_Id                 
            //     }
            // })
          
        }
       
       })
       .catch(error=>{
        console.log(error);
       })
       
     }

     const SearchMemberInf=(ML_Id:string)=>{
        axios.get('https://localhost:44320/api/Member/SearchMemberRegister',
        {
            params:{
                ML_Id:ML_Id
            }
        })
        .then(res=>{
            if(res.data>0)
            {
                alert('即将跳转页');
                router.push({
                    path:'/UserMemberInfo',
                    query:{
                        ML_Id:ML_Id
                    }
                })
            }
            else
            {
                router.push({
                    path:'/addMemberInfo',
                    query:{
                        ML_Id:ML_Id
                    }
                })
            }
        })
     }


</script>